#define DEBUG
#include <cstdio>

using namespace std;

const int mods=1000000007, maxn=5, maxm=5;

int p[maxn+2];

void initP(int n) {
  p[0] = 1;
  for (int i=1; i<=n; i++) {
    p[i] = p[i-1]*10;
  }
}

long long solve(int o, int n, int m, int plan) {
  static bool book[100000], flag[maxm+1];
  if (o<=m) {
    long long ret=solve(o+1, n, m, plan);
    for (int k=1; k<=m; k++) {
      if (!flag[k]) {
	flag[k] = true;
	for (int i=1; i<=n; i++) {
	  int t=plan;
	  for (int j=i; j<=n; j++) {
	    t = t-t/p[j-1]%10*p[j-1]+k*p[j-1];
	    ret = (ret+solve(o+1, n, m, t))%mods;
	  }
	}
	flag[k] = false;
      }
    }
    return ret;
  } else {
    for (int i=1; i<=n; i++) {
      if (plan/p[i-1]%10==0) {
	return 0;
      }
    }
    if (!book[plan]) {
      book[plan] = true;
      return 1;
    } else {
      return 0;
    }
  }
}

int main() {
  freopen("actor.in", "r", stdin);
  freopen("actor.out", "w", stdout);

  int n, m;
  scanf("%d %d", &n, &m);
  initP(n+1);
  printf("%lld", solve(1, n, m, 0));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
